package com.base.themvx.vm

import androidx.lifecycle.ViewModel
import com.base.themvx.AppLog
import com.base.themvx.LibApplication
import com.base.themvx.R
import com.base.themvx.action.LogAction
import com.base.themvx.defNonSyncLazy

/**
 * @author fee
 * <P> DESC:
 * ViewModel的基类
 * 在[MVC]框架下，可以作为[M]
 * 在[MVP]框架下，可以作为[M]
 * 在[MVVM]框架下，作为[VM]
 * </P>
 */
open class BaseViewModel : ViewModel(), LogAction {
    protected val TAG by defNonSyncLazy {
        javaClass.simpleName
    }

    /**
     * Log 输出时的 额外信息
     */
    var extraInfosInDebug: String? = ""

    /**
     * 是否使能Log输出
     * def: false
     */
    var isEnableLogDebug: Boolean = false


    open fun e(tag: String? = defLogTag(), logBodys: String) {
        AppLog.e(tag ?: defLogTag(), logBodys)
    }


    open fun i(tag: String? = defLogTag(), logBodys: String) {
        AppLog.i(tag ?: defLogTag(), logBodys)
    }

    open fun d(logTag: String? = defLogTag(), logBodys: String) {
        AppLog.d(logTag ?: defLogTag(), logBodys)
    }


    private fun defLogTag() = if (extraInfosInDebug.isNullOrBlank()) {
        TAG
    } else "$TAG[$extraInfosInDebug]"

    protected val mReqFailMsg: String
        get() {
            return LibApplication.sApp.getString(R.string.request_data_fail_retry)
        }
}